<?php
class users 
{
        private $uid;
        private $username;
        private $password;
        private $email;
        private $level;
        
        public function get_users($uid)
        {
                $m_query = "select * from users where uid='{$uid}'";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)>0)
                {
                        $m_result = mysql_fetch_assoc($m_sql);
                        $this->uid = $m_result['uid'];
                        $this->username = $m_result['username'];
                        $this->password = $m_result['password'];
                        $this->level = $m_result['level'];
                }
        }
		
		public function get_users2($username)
        {
                $m_query = "select * from users where username='{$username}'";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)>0)
                {
                        $m_result = mysql_fetch_assoc($m_sql);
                        $this->uid = $m_result['uid'];
                        $this->username = $m_result['username'];
                        $this->password = $m_result['password'];
                        $this->level = $m_result['level'];
                }
        }
        
        public function get_uid()
        {
                return $this->uid;
        }
        
        public function get_username()
        {
                return $this->username;
        }
        
        public function get_password()
        {
                return $this->password;
        }
        
        public function get_email()
        {
                return $this->email;
        }

        public function get_level()
        {
                return $this->level;
        }
        
        public function set_uid($uid)
        {
                $this->uid = $uid;
        }
        
        public function set_username($username)
        {
                $this->username = $username;
        }
        
        public function set_password($password)
        {
                $this->password = $password;
        }
        
        public function set_email($email)
        {
                $this->email = $email;
        }
        
        public function set_level($level)
        {
                $this->level = $level;
        }
        
        public function create()
        {
                $m_query = "insert into users (username,password,level)
                                        values ('{$this->username}','{$this->password}','{$this->level}')";
                $m_sql = mysql_query($m_query);
                if($m_sql)
                        return true;
                else return false;
        }
        
        public function update()
        {
                $m_query = "update users 
                                        set password='{$this->password}',
                                                level='{$this->level}' 
                                        where uid={$this->uid}";
                $m_sql = mysql_query($m_query);
                if($m_sql)
                        return true;
                else return false;
        }
        
        public function updatelevel()
        {
                $m_query = "update users 
                                        set level='{$this->level}' 
                                        where uid={$this->uid}";
                $m_sql = mysql_query($m_query);
                if($m_sql)
                        return true;
                else return false;
        }
        
        public function del()
        {
                $m_query = "delete from users where uid={$this->uid}";
                $m_sql = mysql_query($m_query);
                if($m_sql)
                        return true;
                else return false;
        }
        
        static public function check_username($username)
        {
                $m_query = "select username from users where username='{$username}'";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)==1)
                        return '1';
                else return '0';
        }
        
        
        static public function check_login_username($username, $password)
        {
                $m_query = "select uid from users where username='{$username}' and password='{$password}'";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)==1)
                {
                        $m_result = mysql_fetch_assoc($m_sql);
                        return $m_result['uid'];
                }
                else return -1;
        }
        
        static public function check_level($uid)
        {
                $m_query = "select level from users where uid= '{$uid}' ";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)==1)
                {
                        $m_result = mysql_fetch_assoc($m_sql);
                        return $m_result['level'];
                }
                else return -1;
        }
        
        static public function changepass($uid,$pass,$newpass)
        {
                $m_query = "update users set password='{$newpass}' 
                                        where uid='{$uid}' and password='{$pass}'";
                $m_sql = mysql_query($m_query);
                if($m_sql)
                        return '1';
                else return '0';
        }
        
        static public function get_pass($uid)
        {
                $m_query = "select password from users where uid='{$uid}' ";
                $m_sql = mysql_query($m_query);
                if(isset($m_sql) && mysql_num_rows($m_sql)==1)
                {
                        $m_result = mysql_fetch_assoc($m_sql);
                        return $m_result['password'];
                }
                else return -1;
        }

}

?>